package com.spring.di;

import com.spring.app.AppConfig;
import com.spring.service.MyService;
import org.apache.log4j.Logger;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class TestDemo {

    private static Logger logger = Logger.getLogger(TestDemo.class);

    @Test
    public void scanTest_1(){
        AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
        ctx.scan("com.spring.service");
        ctx.refresh();
        MyService myService = ctx.getBean(MyService.class);
        String str = myService.doStuff();
        System.out.println(str);
    }
    @Test
    public void scanTest_2(){
        AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class);
        MyService myService = (MyService) ctx.getBean("myService_1");//ctx.getBean(MyService.class);
        String str = myService.doStuff();
        System.out.println(str);
    }

    public  static void main(String[] args){

    }
}
